lowmap = ['tret','jan','feb','mar','apr','may','jun','jly','aug','sep','oct','nov','dec']
highmap = ['','tam','hel','maa','huh','tou','kes','hei','elo','syy','lok','mer','jou']
def toMars(s):
    if int(s)/13 > 0:
        if int(s)%13 == 0:
            return highmap[int(s)/13]
        return highmap[int(s)/13]+' '+lowmap[int(s)%13]
    else:
        return lowmap[int(s)%13]
def toEarth(s):
    try:
        h,l=s.split(' ')
        return str(highmap.index(h)*13+lowmap.index(l))
    except:
        if s in lowmap:
            return lowmap.index(s)
        else:
            return 13*highmap.index(s)

N=int(raw_input())
while(N>0):
    inputs=raw_input()
    if inputs.isdigit():
        print toMars(inputs)
    else:
        print toEarth(inputs)
    N-=1